#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N = 3e5+5;
vector<int>a[N];
int n,c,k[N];
struct Node{
    int val;
    int pos;
};
vector< Node >vec;
lll cur,tmp,V;
ll ans,b[N];
bool cmp (Node i,Node j){return i.pos < j.pos;}
map<int,int>mp;
vector<int>res;
int main()
{
    freopen("list.in","r",stdin);
    freopen("list.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    for(int i = 1;i <= n;i++)
    {
        cin>>k[i];
        a[i].resize(k[i]);
        for(int j = 0;j < k[i];j++) cin>>a[i][j];
    }
    cin>>c;
    for(int i = 1;i <= n;i++) cin>>b[i],b[i]*=i;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 0;j < k[i];j++)
        {
            tmp -= b[mp[a[i][j]]];
            mp[a[i][j]]++;
            V += c;
            tmp += b[mp[a[i][j]]];
        }
        for(int j = 1;j < k[i];j++) vec.push_back(Node{a[i][j],a[i][j]-a[i][j-1]+1});
    }
    cur = 1;
    ans = tmp+V;
    res.push_back(1);
    sort(vec.begin(),vec.end(),cmp);
    for(int i = 0;i < vec.size();i++)
    {
        int x = vec[i].val;
        tmp += V*(vec[i].pos-cur);
        cur = vec[i].pos;
        V -= c;
        tmp -= b[mp[x]];
        mp[x]--;
        tmp += b[mp[x]];
        if(i+1 == vec.size() || vec[i+1].pos != vec[i].pos)
        {
            if(ans > tmp + V)
            {
                ans = tmp+V;
                res.clear();
                res.push_back(cur);
            }
            else if(ans == tmp + V)
            {
                res.push_back(cur);
            }
        }
    }
    cout<<ans<<" "<<res.size()<<"\n";
    for(auto x:res) cout<<x<<" ";
    cout<<"\n";
    return 0;
}